// 测试全局组件
import MyGlobal from '@/components/MyGlobal'
import PageTools from '@/components/PageTools'
import UploadImg from '@/components/UploadImg'
import ImageHolder from '@/components/ImageHolder'
import store from '@/store'
import Lang from '@/components/Lang'
import ScreenFull from './ScreenFull'

export default {
  install(Vue) {
    Vue.prototype.fun = _ => { console.log('my function') }

    Vue.component('MyGlobal', MyGlobal)
    Vue.component('PageTools', PageTools)
    Vue.component('UploadImg', UploadImg)
    Vue.component('ImageHolder', ImageHolder)
    Vue.component('Lang', Lang)
    Vue.component('ScreenFull', ScreenFull)

    Vue.directive('allow', {
      inserted(el, binding) {
        console.log(111, el, binding)

        const points = store.state.user.userInfo.roles.points
        console.log(222, points)

        if (!points.includes(binding.value)) {
          el.parentNode.remove(el)
        }
      }
    })

    Vue.directive('errorImg', {
      inserted(el, binding) {
        console.log(el, binding)
        if (!binding.value) {
          el.src = 'https://img0.baidu.com/it/u=4097141482,1340018504&fm=253&fmt=auto&app=138&f=JPEG?w=507&h=500'
        }

        el.onerror = () => {
          el.src = 'https://img0.baidu.com/it/u=4097141482,1340018504&fm=253&fmt=auto&app=138&f=JPEG?w=507&h=500'
        }
      }
    })
  }
}
